package com.mycontact.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.mycontact.client.place.ViewContactsPlace;
import com.mycontact.client.place.EditContactPlace;
import com.mycontact.client.ClientFactory;

public class TopPanel extends Composite {
	private static TopPanelUiBinder uiBinder = GWT.create(TopPanelUiBinder.class);
	@UiField Button butViewContacts;
	@UiField Button butEditContact;
	private ClientFactory clientFactory;

	interface TopPanelUiBinder extends UiBinder<Widget, TopPanel> { }

	public TopPanel() {
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	public void setClientFactory(ClientFactory cf) {
		clientFactory = cf;
	}
	
	@UiHandler("butViewContacts")
	void onButViewContactsClick(ClickEvent event) {
		if(clientFactory != null) {
			clientFactory.getPlaceController().goTo(new ViewContactsPlace());
		}
	}
	
	@UiHandler("butEditContact")
	void onButEditContactClick(ClickEvent event) {
		clientFactory.getPlaceController().goTo(new EditContactPlace(clientFactory.getSelectedContactId()));
	}
}
